package com.example;

import java.util.concurrent.CountDownLatch;

//TIP 要<b>运行</b>代码，请按 <shortcut actionId="Run"/> 或
// 点击装订区域中的 <icon src="AllIcons.Actions.Execute"/> 图标。
public class Main {

    static int count = 0;
    static CountDownLatch cdl = new CountDownLatch (1000);

    public static void main (String [] args) throws Exception {
        CountRunnable countRunnable = new CountRunnable();
        for (int i = 0; i < 1000; i++) {
            new Thread(countRunnable).start();
        }
        cdl.await();
//        System.out.println(count);
    }

    static class CountRunnable implements Runnable {
        private void count() {
            for (int i = 0; i < 1000; i++) {
                count++;
            }
            System.out.println("in:" + count);
        }

        @Override
        public void run() {
            count();
            cdl.countDown();
        }

    }
}